<head>
<script>

    /* logging */
    var messages = [];
    var log = function (message) {
        messages.push(message);
    };
    window.onload = function () {
        log = function (message) {
            var p = document.createElement('p');
            p.innerHTML = message;
            document.body.appendChild(p);
        };
        for (var i = 0; i < messages.length; i++) {
            log(messages[i]);
        }
    };

    var finishedCallbacks = {};
    var request = function (url, finished) {

        /*
        Inspired by code by Andrea Giammarchi 
        http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html 
        */
        var head = document.getElementsByTagName("head")[0] || document.documentElement;
        var script = document.createElement('script');
        script.src =  url;
        head.appendChild(script);

        finishedCallbacks[url] = finished;

        var script = document.createElement('script');
        script.appendChild(document.createTextNode("finishedCallbacks['" + url + "']()"));
        head.appendChild(script);
    }

    log('sending requests');
    request("crossSite.php?n=1", function () {log('1 finished')});
    request("crossSite.php?n=2", function () {log('2 finished')});
    request("crossSite.php?n=3", function () {log('3 finished')});
    request("crossSite.php?n=4", function () {log('4 finished')});
    log('all requests sent');

</script>
</head>
